package logic

import (
	"context"
	"errors"
	"srv/models/mysqlinit"

	"srv/internal/svc"
	"srv/srv"

	"github.com/zeromicro/go-zero/core/logx"
)

type ExamineLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewExamineLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ExamineLogic {
	return &ExamineLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ExamineLogic) Examine(in *srv.ExamineRequest) (*srv.ExamineResponse, error) {
	// todo: add your logic here and delete this line
	u := mysqlinit.User{}
	mysqlinit.DB.Debug().Where("id = ?", in.UserId).Find(&u)

	if u.ID == 0 {
		logx.Error("用户不存在")
		return nil, errors.New("用户不存在")
	}
	u = mysqlinit.User{

		Real:        in.Real,
		IdCord:      in.IdCord,
		StraightUrl: in.StraightUrl,
		ReverseUrl:  in.ReverseUrl,
	}
	mysqlinit.DB.Debug().Where("id = ?", in.UserId).Updates(&u)

	return &srv.ExamineResponse{
		Type: true,
	}, nil
}
